#include "widget.h"
#include "ui_widget.h"
#include <QPushButton>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    this->resize(600,400);
    zt = new Teacher(this);
    st = new Student(this);

    // 连接
//    connect(zt, &Teacher::hungry, st, &Student::treat);
//    classIsOver();
    // 指针-》地址
    void(Teacher::*teacherSignal)(QString) =  &Teacher::hungry;
    void(Student::*studentSlot)(QString) =  &Student::treat;

    connect(zt, teacherSignal, st, studentSlot);
    //classIsOver();

    QPushButton *btn=new QPushButton("下课", this);

    // 点击按钮触发下课
    connect(btn, &QPushButton::clicked, this, &Widget::classIsOver);


    void(Teacher::*teacherSignal2)(void) =  &Teacher::hungry;
    void(Student::*studentSlot2)(void) =  &Student::treat;

    connect(zt, teacherSignal2, st, studentSlot2);

    connect(btn, &QPushButton::clicked, zt, teacherSignal2);
    //disconnect(zt, teacherSignal2, st, studentSlot2);

//    [=](){
//        btn->setText("aaa");
//    }();


    QPushButton *btn2=new QPushButton("关闭", this);
    btn2->move(100,20);

    qw = new QWidget(this);
    qw->resize(100,100);
    qw->setWindowTitle("666");
    //qw->show();
    connect(btn2, &QPushButton::clicked, qw, &QWidget::show);
}

void Widget::classIsOver() {
    emit zt->hungry("宫保鸡丁");
}

Widget::~Widget()
{
    delete ui;
}

